﻿//  Copyright (c) 2011 Ray Liang (http://www.dotnetage.com)
//  Licensed MIT: http://www.opensource.org/licenses/mit-license.php

using System;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

namespace DNA.Mvc.Publishing
{
    [Table("publishing_articles")]
    public class Article
    {
        [Key]
        public virtual int ID { get; set; }

        public virtual int CategoryID { get; set; }

        [ForeignKey("CategoryID")]
        public virtual Category Category { get; set; }
        
        [Required]
        public virtual bool AllowComments { get; set; }

        [Required]
        public virtual bool AllowPingback { get; set; }

        [Column(TypeName="ntext")]
        public virtual string Body { get; set; }

        [MaxLength(1024)]
        public virtual string Categories { get; set; }
        
        [Required]
        public virtual int ContentFormat { get; set; }
        
        [MaxLength(1024)]
        public virtual string ImageUrl { get; set; }

        [Required]
        public virtual bool IsAppoved { get; set; }

        [Required]
        public virtual bool IsPrivate { get; set; }

        [Required]
        public virtual bool IsPublished { get; set; }

        [MaxLength(50)]
        public virtual string Language { get; set; }

        [Required]
        public virtual DateTime LastModified { get; set; }

        public virtual int ParentID { get; set; }

        [MaxLength(50)]
        public virtual string Password { get; set; }

        [MaxLength(1024)]
        public virtual string Path { get; set; }

        [MaxLength(1024)]
        public virtual string PermaLink { get; set; }

        [Column(TypeName="ntext")]
        public virtual string PingUrls { get; set; }

        [Required]
        public virtual int Pos { get; set; }

        [Required]
        public virtual DateTime Posted { get; set; }

        public virtual double Ratings { get; set; }

        public string RelatedPosts { get; set; }

        public virtual string SendTrackbackUrls { get; set; }

        [MaxLength(1024)]
        public virtual string Slug { get; set; }

        [Column(TypeName="ntext")]
        public virtual string Summary { get; set; }

        [MaxLength(255)]
        public virtual string Tags { get; set; }

        [MaxLength(255),Required]
        public virtual string Title { get; set; }

        public virtual int TotalReads { get; set; }

        [Required]
        public virtual int TotalComments { get; set; }

        [Required]
        public virtual int TotalVotes { get; set; }

        [MaxLength(50)]
        public virtual string UserName { get; set; }

        [Required]
        public virtual int Version { get; set; }

        public virtual ICollection<Track> Tracks { get; set; }

        public virtual ICollection<Vote> Votes { get; set; }

        public virtual ICollection<TranslatedCopy> TranslatedCopies { get; set; }

        public virtual ICollection<History> Versions { get; set; }

        public virtual ICollection<Comment> Comments { get; set; }

        /// <summary>
        /// Determine the specified user is article owner.
        /// </summary>
        /// <param name="username">The user name.</param>
        /// <returns></returns>
        public virtual bool IsOwner(string username)
        {
            return UserName.Equals(username, StringComparison.OrdinalIgnoreCase);
        }
    }
}
